For this project, we sought to determine the different customer
archetypes for Food and Beverage categories. To accomplish this, we will
perform a cluster analysis based on the spending habits, customer
attributes, and customer reactions to a series of marketing
campaigns.
It is vital for businesses to understand their customers and how they
are grouped. By understanding the different customer segments, a
business can create more targeted advertisements that cater to each
group and adjust products and services for specific customer needs to
drive greater revenue and profits. We hope that by doing this analysis,
businesses in the Food and Beverage space can make more informed
decisions and advance further growth.
The dataset is provided by Dr. Omar Romero-Hernandez, a researcher
and professor at U.C. Berkeley’s Haas School of Business and the Hult
International Business School. Unfortunately, there is no information
provided on how the data was collected. The link to it can be found
here: https://www.kaggle.com/datasets/imakash3011/customer-personality-analysis
The dataset contains 27 columns and 2240 rows, and can be thematically
divided into 3 sections:
Libraries
# libraries
library(remotes)
if(!require(remotes)){
install.packages("remotes")
}
remotes::install_github("rkabacoff/qacDR")
## Skipping install of 'qacDR' from a github remote, the SHA1 (fd1d6a06) has not changed since last install.
## Use `force = TRUE` to force installation
library(readr)
library(qacBase)
library(qacDR)
##
## Attaching package: 'qacDR'
## The following objects are masked from 'package:qacBase':
##
## normalize, standardize
library(mice)
##
## Attaching package: 'mice'
## The following object is masked from 'package:stats':
##
## filter
## The following objects are masked from 'package:base':
##
## cbind, rbind
library(VIM)
## Loading required package: colorspace
## Loading required package: grid
## VIM is ready to use.
## Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues
##
## Attaching package: 'VIM'
## The following object is masked from 'package:datasets':
##
## sleep
library(tidyverse)
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Rmpfr'
## Also defined by 'Matrix'
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ dplyr 1.0.10
## ✔ tibble 3.1.8 ✔ stringr 1.4.1
## ✔ tidyr 1.2.1 ✔ forcats 0.5.2
## ✔ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks mice::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(ggplot2)
library(vcd)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(reshape2)
##
## Attaching package: 'reshape2'
##
## The following object is masked from 'package:tidyr':
##
## smiths
Loading the Data
# load the data
market <- read_delim("https://raw.githubusercontent.com/amankharwal/Website-data/master/marketing_campaign.csv", delim = ";", escape_double = FALSE, trim_ws = TRUE)
## Rows: 2240 Columns: 29
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (2): Education, Marital_Status
## dbl (26): ID, Year_Birth, Income, Kidhome, Teenhome, Recency, MntWines, Mnt...
## date (1): Dt_Customer
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# convert data to a data frame
market <- as.data.frame(market)
Data Management and Univariate Analysis
In this section of code, we analyzed each of the variables individually.
This allowed us to identify variables that are not needed, identify and
remove outliers (an important step for k-means clustering), and turn
ordinal/nominal data into factors. We performed six major data
management executions.
First, we omitted missing values with listwise deletion. This is because we only had 24 missing values out of 2240 observations, which were centered on the one variable Income. Since this is a very small number of missing data, in which removing such values would have a negligible impact on further analyses, we did not need to resort to kNN imputation.
# checking the contents
contents(market)
##
## The data frame market has 2,240 observations and 29 variables.
##
## Overall
## pos varname type n_unique n_miss pct_miss
## 1 ID numeric 2240 0 0%
## 2 Year_Birth numeric 59 0 0%
## 3 Education character 5 0 0%
## 4 Marital_Status character 8 0 0%
## 5 Income numeric 1975 24 1%
## 6 Kidhome numeric 3 0 0%
## 7 Teenhome numeric 3 0 0%
## 8 Dt_Customer Date 663 0 0%
## 9 Recency numeric 100 0 0%
## 10 MntWines numeric 776 0 0%
## 11 MntFruits numeric 158 0 0%
## 12 MntMeatProducts numeric 558 0 0%
## 13 MntFishProducts numeric 182 0 0%
## 14 MntSweetProducts numeric 177 0 0%
## 15 MntGoldProds numeric 213 0 0%
## 16 NumDealsPurchases numeric 15 0 0%
## 17 NumWebPurchases numeric 15 0 0%
## 18 NumCatalogPurchases numeric 14 0 0%
## 19 NumStorePurchases numeric 14 0 0%
## 20 NumWebVisitsMonth numeric 16 0 0%
## 21 AcceptedCmp3 numeric 2 0 0%
## 22 AcceptedCmp4 numeric 2 0 0%
## 23 AcceptedCmp5 numeric 2 0 0%
## 24 AcceptedCmp1 numeric 2 0 0%
## 25 AcceptedCmp2 numeric 2 0 0%
## 26 Complain numeric 2 0 0%
## 27 Z_CostContact numeric 1 0 0%
## 28 Z_Revenue numeric 1 0 0%
## 29 Response numeric 2 0 0%
##
## Numeric Variables
## n mean sd skew min p25 median p75
## ID 2240 5592.16 3246.66 0.04 0 2828.25 5458.5 8427.75
## Year_Birth 2240 1968.81 11.98 -0.35 1893 1959.00 1970.0 1977.00
## Income 2216 52247.25 25173.08 6.75 1730 35303.00 51381.5 68522.00
## Kidhome 2240 0.44 0.54 0.63 0 0.00 0.0 1.00
## Teenhome 2240 0.51 0.54 0.41 0 0.00 0.0 1.00
## Recency 2240 49.11 28.96 0.00 0 24.00 49.0 74.00
## MntWines 2240 303.94 336.60 1.17 0 23.75 173.5 504.25
## MntFruits 2240 26.30 39.77 2.10 0 1.00 8.0 33.00
## MntMeatProducts 2240 166.95 225.72 2.08 0 16.00 67.0 232.00
## MntFishProducts 2240 37.53 54.63 1.92 0 3.00 12.0 50.00
## MntSweetProducts 2240 27.06 41.28 2.13 0 1.00 8.0 33.00
## MntGoldProds 2240 44.02 52.17 1.88 0 9.00 24.0 56.00
## NumDealsPurchases 2240 2.33 1.93 2.42 0 1.00 2.0 3.00
## NumWebPurchases 2240 4.08 2.78 1.38 0 2.00 4.0 6.00
## NumCatalogPurchases 2240 2.66 2.92 1.88 0 0.00 2.0 4.00
## NumStorePurchases 2240 5.79 3.25 0.70 0 3.00 5.0 8.00
## NumWebVisitsMonth 2240 5.32 2.43 0.21 0 3.00 6.0 7.00
## AcceptedCmp3 2240 0.07 0.26 3.29 0 0.00 0.0 0.00
## AcceptedCmp4 2240 0.07 0.26 3.24 0 0.00 0.0 0.00
## AcceptedCmp5 2240 0.07 0.26 3.29 0 0.00 0.0 0.00
## AcceptedCmp1 2240 0.06 0.25 3.55 0 0.00 0.0 0.00
## AcceptedCmp2 2240 0.01 0.11 8.46 0 0.00 0.0 0.00
## Complain 2240 0.01 0.10 10.18 0 0.00 0.0 0.00
## Z_CostContact 2240 3.00 0.00 NaN 3 3.00 3.0 3.00
## Z_Revenue 2240 11.00 0.00 NaN 11 11.00 11.0 11.00
## Response 2240 0.15 0.36 1.97 0 0.00 0.0 0.00
## max
## ID 11191
## Year_Birth 1996
## Income 666666
## Kidhome 2
## Teenhome 2
## Recency 99
## MntWines 1493
## MntFruits 199
## MntMeatProducts 1725
## MntFishProducts 259
## MntSweetProducts 263
## MntGoldProds 362
## NumDealsPurchases 15
## NumWebPurchases 27
## NumCatalogPurchases 28
## NumStorePurchases 13
## NumWebVisitsMonth 20
## AcceptedCmp3 1
## AcceptedCmp4 1
## AcceptedCmp5 1
## AcceptedCmp1 1
## AcceptedCmp2 1
## Complain 1
## Z_CostContact 3
## Z_Revenue 11
## Response 1
##
## Categorical Variables
## variable level n pct
## Education 2n Cycle 203 0.09
## Basic 54 0.02
## Graduation 1127 0.50
## Master 370 0.17
## PhD 486 0.22
## Marital_Status Absurd 2 0.00
## Alone 3 0.00
## Divorced 232 0.10
## Married 864 0.39
## Single 480 0.21
## Together 580 0.26
## Widow 77 0.03
## YOLO 2 0.00
# visiualizing missing data
md.pattern(market, rotate.names = T)
## ID Year_Birth Education Marital_Status Kidhome Teenhome Dt_Customer
## 2216 1 1 1 1 1 1 1
## 24 1 1 1 1 1 1 1
## 0 0 0 0 0 0 0
## Recency MntWines MntFruits MntMeatProducts MntFishProducts
## 2216 1 1 1 1 1
## 24 1 1 1 1 1
## 0 0 0 0 0
## MntSweetProducts MntGoldProds NumDealsPurchases NumWebPurchases
## 2216 1 1 1 1
## 24 1 1 1 1
## 0 0 0 0
## NumCatalogPurchases NumStorePurchases NumWebVisitsMonth AcceptedCmp3
## 2216 1 1 1 1
## 24 1 1 1 1
## 0 0 0 0
## AcceptedCmp4 AcceptedCmp5 AcceptedCmp1 AcceptedCmp2 Complain Z_CostContact
## 2216 1 1 1 1 1 1
## 24 1 1 1 1 1 1
## 0 0 0 0 0 0
## Z_Revenue Response Income
## 2216 1 1 1 0
## 24 1 1 0 1
## 0 0 24 24
# omit missing data
market = na.omit(market)
Second, we removed variables ID, Z_CostContact,
Z_Revenue, Dt_Customer, and Complain. This is because they were either
redundant, as in the case of ID, or had no explanation for their values,
as in the case of Z_CostContact and Z_Revenue, or were not necessary for
our particular analysis, as in the case of Dt_Customer and
Complain.
More specific explanations will be provided next to each data
manipulation.
# delete id
market = market %>% select(-ID)
# Exploring Z_CostContact and Z_Revenue
z <- market %>% select(Z_CostContact, Z_Revenue)
head(z, 20)
#Deleting Z_CostContact and Z_Revenue
market = market %>% select(-Z_CostContact, -Z_Revenue)
Don’t need each customer’s unique ID– hence, remove.
Unsure what Z_CostContract and Z_Revenue mean as they were not provided
with the data description– hence, remove.
# Exploring Complaints
market$Complain
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
## [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [112] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
## [149] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
## [186] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [223] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [260] 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [297] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [334] 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [371] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [408] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [445] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [482] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [519] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [556] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [593] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [630] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [667] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [704] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [741] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [778] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [815] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [852] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [889] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [926] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
## [963] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1000] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
## [1037] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1074] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1111] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1148] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1185] 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1222] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1259] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1296] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1333] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1370] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1407] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1444] 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1481] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1518] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1555] 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1592] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1629] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1666] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1703] 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1740] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1777] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1814] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1851] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1888] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1925] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1962] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [1999] 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [2036] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [2073] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [2110] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [2147] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [2184] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# Deleting Complain
market = market %>% select(-Complain)
Very low percentage of negative complaints and so it was treated as negligible– hence, remove.
# Exploring Dt_Customer
head(market$Dt_Customer)
## [1] "2012-09-04" "2014-03-08" "2013-08-21" "2014-02-10" "2014-01-19"
## [6] "2013-09-09"
#Deleting Dt_Customer
market = market %>% select(-Dt_Customer)
Don’t need date of each customer’s enrollment in the company for our analysis– hence, remove.
Third, we removed outliers in variable Year_Birth and transformed it into a new variable Age. Changing date of birth into age (in years) eases comprehension, particularly when visualizing data.
# Exploring Year of Birth
table(market$Year_Birth)
##
## 1893 1899 1900 1940 1941 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
## 1 1 1 1 1 6 7 8 16 16 21 30 29 42 52 35
## 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969
## 49 48 55 41 52 50 49 35 44 44 41 74 50 44 51 70
## 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
## 75 86 78 72 69 83 89 52 76 53 39 38 44 41 38 32
## 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
## 41 27 29 29 18 15 13 5 3 5 2
# Removing for Outliers in Year_Birth
summary(market$Year_Birth)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1893 1959 1970 1969 1977 1996
outlier = boxplot(market$Year_Birth, plot=T)$out
market = market[-which(market$Year_Birth %in% outlier),]
boxplot(market$Year_Birth)
# Get the Age from year of birth
market$reference <- 2015
market$Age <- market$reference - market$Year_Birth
market <- market %>% select(-c("Year_Birth","reference"))
Fourth, we removed unusual answers in variable Marital_Status that were likely answered as a joke. We then collapsed similar responses into a factor with two levels: “1”, which indicates one is not legally married, and “2”, which indicates one is married.
# Exploring Marital Status
ggplot(market) + geom_bar(aes(x=Marital_Status))
# Removing unusual answers
market = market %>%
filter(Marital_Status != "YOLO") %>%
filter(Marital_Status != "Alone") %>%
filter(Marital_Status != "Absurd")
# Converting to Factor
market$Marital_Status <- fct_collapse(market$Marital_Status,
"1" = c("Divorced","Single","Widow"),"2" = c("Married","Together"))
market$Marital_Status <- as.numeric(levels(market$Marital_Status))[market$Marital_Status]
Fifth, we converted variable Education into a factor of three levels: “1”, which is a receiver of basic education, “2”, which is an undergraduate degree-holder, and “3”, which is a higher education degree-holder.
# Exploring Education
ggplot(market) + geom_bar(aes(x=Education))
# Converting to Factor
market$Education <- fct_collapse(market$Education,
"3" = c("2n Cycle", "Master","PhD"),"1" = "Basic",
"2" = "Graduation")
market$Education <- as.numeric(levels(market$Education))[market$Education]
Finally, we removed outliers in variable Income. This is performed because such outliers could skew further analyses.
# Exploring Income
ggplot(market) + geom_histogram(aes(x=Income), bins = 100)
#Removing Outliers in Income
summary(market$Income)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1730 35208 51382 52233 68592 666666
outliers = boxplot(market$Income, plot=T)$out
market = market[-which(market$Income %in% outliers),]
boxplot(market$Income)
Exploring the rest of the Data
We then explored the rest of the dataset, scanning for any other data
management decisions we could undertake – and of course, to also
familiarize ourselves with all the data!
# Exploring Kidhome
ggplot(market) + geom_bar(aes(x=Kidhome))
This will be useful for further analysis and there contains no unusual data.
# Exploring Teenhome
ggplot(market) + geom_bar(aes(x=Teenhome))
This will be useful for further analysis and there contains no unusual data.
# Exploring Recency
ggplot(market) + geom_histogram(aes(x=Recency), bins = 100)
This appears to be evenly distributed.
# Exploring amount spent on products
amt_spnt <- market %>% select(MntWines,MntFruits,MntMeatProducts,MntFishProducts,MntSweetProducts,MntGoldProds)
head(amt_spnt)
This will be useful for further analysis.
# Exploring customer actions
num_actions <- market %>% select(NumDealsPurchases,NumCatalogPurchases,NumWebPurchases,NumStorePurchases,NumWebVisitsMonth)
head(num_actions)
This will be useful for further analysis.
# Exploring Recency
head(market$Recency)
## [1] 58 38 26 26 94 16
This will be useful for further analysis.
After exploring all the data, we realized just how vast the dataset was – and that we could ease comprehension by reducing the number of features. This led us to doing a Principal Component Analysis.
PCA Anlysis
# Doing PCA
fit = PCA(market)
##
## Principal Components Analysis
## Number of Factors: 24 Rotation: none
##
## Component Structure
## PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10
## Education 0.04 0.24 0.13 -0.25 -0.49 0.30 -0.01 0.61 -0.20 0.17
## Marital_Status -0.03 0.07 -0.06 -0.15 0.27 0.87 0.18 -0.24 0.01 0.01
## Income 0.88 0.13 -0.03 -0.15 -0.07 0.03 -0.01 0.04 0.02 0.00
## Kidhome -0.65 -0.13 0.12 0.21 0.14 0.13 -0.07 0.22 0.19 0.29
## Teenhome -0.13 0.77 -0.07 -0.08 -0.10 -0.06 0.12 -0.19 0.12 0.08
## Recency 0.00 0.04 -0.15 -0.19 0.49 -0.26 0.59 0.47 0.13 0.04
## MntWines 0.79 0.25 0.26 -0.04 0.06 0.04 -0.01 0.12 -0.06 -0.16
## MntFruits 0.68 -0.18 -0.28 0.17 0.04 -0.01 -0.08 -0.03 0.00 0.18
## MntMeatProducts 0.82 -0.20 -0.06 0.03 -0.01 0.03 -0.03 0.12 0.08 0.04
## MntFishProducts 0.71 -0.19 -0.27 0.14 0.05 0.00 -0.06 -0.04 0.05 0.23
## MntSweetProducts 0.69 -0.16 -0.23 0.13 0.09 0.01 -0.06 0.00 0.08 0.20
## MntGoldProds 0.56 0.11 -0.11 0.38 0.10 -0.07 0.16 -0.14 -0.12 -0.08
## NumDealsPurchases -0.15 0.65 0.05 0.45 0.21 0.07 -0.15 0.15 0.13 0.21
## NumWebPurchases 0.55 0.49 0.03 0.30 0.10 0.05 -0.07 0.08 -0.05 -0.20
## NumCatalogPurchases 0.84 0.02 -0.02 0.06 -0.05 0.01 0.10 0.05 -0.01 0.02
## NumStorePurchases 0.74 0.28 -0.15 -0.03 0.08 0.04 -0.14 0.06 -0.19 -0.06
## NumWebVisitsMonth -0.64 0.23 0.26 0.37 0.18 0.01 -0.07 0.06 0.01 -0.03
## AcceptedCmp3 0.05 -0.12 0.28 0.47 -0.29 0.08 0.62 -0.07 -0.16 -0.11
## AcceptedCmp4 0.25 0.19 0.56 -0.31 0.29 -0.12 -0.20 -0.03 -0.02 -0.18
## AcceptedCmp5 0.49 -0.21 0.50 -0.16 0.10 0.08 0.04 0.03 0.20 -0.14
## AcceptedCmp1 0.44 -0.18 0.44 -0.03 0.07 0.09 0.06 -0.05 0.44 0.12
## AcceptedCmp2 0.15 0.03 0.53 -0.16 0.22 -0.14 0.10 -0.23 -0.50 0.50
## Response 0.28 -0.14 0.59 0.35 -0.31 -0.06 -0.09 0.02 0.15 0.06
## Age 0.16 0.51 -0.07 -0.30 -0.35 -0.15 0.22 -0.28 0.33 0.18
## PC11 PC12 PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20
## Education 0.18 -0.11 -0.04 0.17 0.07 0.02 -0.02 -0.07 -0.02 -0.01
## Marital_Status 0.10 0.16 0.00 0.00 -0.03 -0.11 0.01 0.03 -0.01 0.01
## Income -0.17 -0.03 0.01 0.00 0.02 -0.01 0.04 0.17 0.09 -0.04
## Kidhome -0.23 0.04 -0.04 0.11 -0.04 0.27 0.08 0.33 0.10 -0.06
## Teenhome -0.26 -0.14 0.07 0.16 0.17 -0.27 0.06 -0.05 0.21 -0.02
## Recency 0.10 0.11 0.00 -0.02 0.01 -0.16 0.04 0.04 -0.03 0.06
## MntWines -0.05 0.03 0.00 -0.12 -0.04 0.12 0.06 -0.07 0.08 -0.04
## MntFruits 0.05 0.10 0.19 0.17 0.16 0.00 0.46 -0.11 -0.13 -0.13
## MntMeatProducts -0.09 0.15 -0.04 -0.13 -0.16 0.00 0.01 -0.08 0.13 -0.14
## MntFishProducts 0.15 -0.03 0.10 0.13 -0.09 0.08 -0.05 -0.09 0.31 0.38
## MntSweetProducts 0.03 0.01 0.23 0.06 0.31 -0.02 -0.40 0.04 -0.14 -0.13
## MntGoldProds 0.19 -0.11 -0.49 0.35 -0.01 0.05 -0.03 0.06 -0.05 -0.06
## NumDealsPurchases -0.21 0.07 -0.06 0.00 -0.16 0.00 -0.09 -0.19 -0.17 0.04
## NumWebPurchases 0.21 -0.06 0.07 -0.21 0.19 0.05 0.02 0.25 0.14 -0.04
## NumCatalogPurchases -0.07 0.08 -0.05 -0.08 -0.25 -0.01 -0.09 -0.13 0.09 -0.21
## NumStorePurchases -0.15 -0.08 0.05 -0.12 -0.07 0.03 0.07 0.11 -0.28 0.27
## NumWebVisitsMonth 0.30 0.03 0.10 -0.11 0.13 0.12 0.05 -0.20 0.09 -0.02
## AcceptedCmp3 -0.17 -0.04 0.30 0.07 -0.05 0.13 -0.02 0.00 -0.04 0.04
## AcceptedCmp4 0.09 0.11 0.28 0.40 -0.19 0.04 -0.06 0.04 -0.01 -0.04
## AcceptedCmp5 -0.24 0.12 -0.22 0.04 0.39 0.17 -0.01 -0.16 0.00 0.13
## AcceptedCmp1 0.14 -0.55 0.02 -0.09 -0.11 -0.05 0.06 -0.02 -0.09 -0.03
## AcceptedCmp2 0.01 -0.02 -0.07 -0.14 0.06 0.00 0.01 0.01 0.02 -0.02
## Response 0.11 0.31 -0.06 -0.02 -0.01 -0.39 0.03 0.14 -0.04 0.11
## Age 0.22 0.24 -0.02 -0.07 -0.04 0.29 0.00 0.05 -0.11 0.02
## PC21 PC22 PC23 PC24 h2
## Education -0.02 0.02 0.02 -0.01 1
## Marital_Status 0.02 0.00 -0.01 0.00 1
## Income 0.02 0.04 -0.10 0.29 1
## Kidhome 0.10 -0.05 0.05 -0.05 1
## Teenhome 0.11 0.02 0.07 -0.06 1
## Recency 0.00 -0.01 0.00 0.00 1
## MntWines 0.22 -0.10 -0.27 -0.12 1
## MntFruits -0.06 -0.05 -0.01 -0.01 1
## MntMeatProducts 0.04 0.37 0.07 -0.06 1
## MntFishProducts -0.03 -0.03 -0.02 -0.01 1
## MntSweetProducts 0.11 -0.01 -0.03 -0.02 1
## MntGoldProds 0.07 0.05 0.00 0.00 1
## NumDealsPurchases -0.18 0.03 -0.10 0.04 1
## NumWebPurchases -0.26 0.00 0.05 -0.06 1
## NumCatalogPurchases 0.00 -0.28 0.20 0.02 1
## NumStorePurchases 0.19 0.02 0.17 -0.02 1
## NumWebVisitsMonth 0.25 0.04 0.09 0.13 1
## AcceptedCmp3 -0.03 0.05 -0.01 0.00 1
## AcceptedCmp4 -0.04 0.04 0.04 -0.01 1
## AcceptedCmp5 -0.09 -0.02 0.08 0.00 1
## AcceptedCmp1 -0.01 0.01 0.00 -0.01 1
## AcceptedCmp2 -0.04 0.02 0.00 0.00 1
## Response 0.06 -0.04 -0.01 -0.01 1
## Age 0.00 0.01 0.00 0.00 1
##
## PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 PC11 PC12
## Variance 6.87 2.09 1.92 1.43 1.17 1.02 1.00 0.96 0.84 0.73 0.66 0.63
## Var Explained 0.29 0.09 0.08 0.06 0.05 0.04 0.04 0.04 0.04 0.03 0.03 0.03
## Cum Var Explained 0.29 0.37 0.45 0.51 0.56 0.60 0.65 0.69 0.72 0.75 0.78 0.81
## PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20 PC21 PC22 PC23 PC24
## Variance 0.61 0.55 0.54 0.50 0.43 0.40 0.39 0.36 0.31 0.25 0.20 0.13
## Var Explained 0.03 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.01 0.01 0.01 0.01
## Cum Var Explained 0.83 0.85 0.88 0.90 0.92 0.93 0.95 0.96 0.98 0.99 0.99 1.00
# Plotting scree plot
scree_plot(market)
# Chose 5 PCs
fit = PCA(market, nfactors = 5)
##
## Principal Components Analysis
## Number of Factors: 5 Rotation: none
##
## Component Structure
## PC1 PC2 PC3 PC4 PC5 h2
## Education 0.04 0.24 0.13 -0.25 -0.49 0.38
## Marital_Status -0.03 0.07 -0.06 -0.15 0.27 0.11
## Income 0.88 0.13 -0.03 -0.15 -0.07 0.83
## Kidhome -0.65 -0.13 0.12 0.21 0.14 0.52
## Teenhome -0.13 0.77 -0.07 -0.08 -0.10 0.63
## Recency 0.00 0.04 -0.15 -0.19 0.49 0.30
## MntWines 0.79 0.25 0.26 -0.04 0.06 0.76
## MntFruits 0.68 -0.18 -0.28 0.17 0.04 0.60
## MntMeatProducts 0.82 -0.20 -0.06 0.03 -0.01 0.71
## MntFishProducts 0.71 -0.19 -0.27 0.14 0.05 0.63
## MntSweetProducts 0.69 -0.16 -0.23 0.13 0.09 0.58
## MntGoldProds 0.56 0.11 -0.11 0.38 0.10 0.49
## NumDealsPurchases -0.15 0.65 0.05 0.45 0.21 0.69
## NumWebPurchases 0.55 0.49 0.03 0.30 0.10 0.65
## NumCatalogPurchases 0.84 0.02 -0.02 0.06 -0.05 0.71
## NumStorePurchases 0.74 0.28 -0.15 -0.03 0.08 0.65
## NumWebVisitsMonth -0.64 0.23 0.26 0.37 0.18 0.70
## AcceptedCmp3 0.05 -0.12 0.28 0.47 -0.29 0.40
## AcceptedCmp4 0.25 0.19 0.56 -0.31 0.29 0.60
## AcceptedCmp5 0.49 -0.21 0.50 -0.16 0.10 0.57
## AcceptedCmp1 0.44 -0.18 0.44 -0.03 0.07 0.42
## AcceptedCmp2 0.15 0.03 0.53 -0.16 0.22 0.38
## Response 0.28 -0.14 0.59 0.35 -0.31 0.66
## Age 0.16 0.51 -0.07 -0.30 -0.35 0.50
##
## PC1 PC2 PC3 PC4 PC5
## Variance 6.87 2.09 1.92 1.43 1.17
## Var Explained 0.29 0.09 0.08 0.06 0.05
## Cum Var Explained 0.29 0.37 0.45 0.51 0.56
#Explains 56% of Var
plot(fit, sort = T)
Based on the scree plot, we used five factors for our principle component analysis. After plotting the results, we got a cumulative variance of 56%. The variance was low because we believe that the different types of data that we had (factors, ages, income) all varied vastly in numbers, making it difficult to project in two dimensions.
Cluster Analysis
Now, we were ready to perform a k-means cluster analysis. First, we used
a WSS plot to find the optimal number of clusters. Then, we utilized
NbClust to validate this finding.
# Finding the best number of clusters for k-means
library(NbClust)
market_st = standardize(market)
contents(market_st)
##
## The data frame market_st has 2,198 observations and 24 variables.
##
## Overall
## pos varname type n_unique n_miss pct_miss
## 1 Education numeric 3 0 0%
## 2 Marital_Status numeric 2 0 0%
## 3 Income numeric 1961 0 0%
## 4 Kidhome numeric 3 0 0%
## 5 Teenhome numeric 3 0 0%
## 6 Recency numeric 100 0 0%
## 7 MntWines numeric 774 0 0%
## 8 MntFruits numeric 158 0 0%
## 9 MntMeatProducts numeric 551 0 0%
## 10 MntFishProducts numeric 182 0 0%
## 11 MntSweetProducts numeric 176 0 0%
## 12 MntGoldProds numeric 211 0 0%
## 13 NumDealsPurchases numeric 15 0 0%
## 14 NumWebPurchases numeric 15 0 0%
## 15 NumCatalogPurchases numeric 13 0 0%
## 16 NumStorePurchases numeric 14 0 0%
## 17 NumWebVisitsMonth numeric 16 0 0%
## 18 AcceptedCmp3 numeric 2 0 0%
## 19 AcceptedCmp4 numeric 2 0 0%
## 20 AcceptedCmp5 numeric 2 0 0%
## 21 AcceptedCmp1 numeric 2 0 0%
## 22 AcceptedCmp2 numeric 2 0 0%
## 23 Response numeric 2 0 0%
## 24 Age numeric 56 0 0%
##
## Numeric Variables
## n mean sd skew min p25 median p75 max
## Education 2198 0.00 1.00 -0.24 -2.66 -0.82 -0.82 1.02 1.02
## Marital_Status 2198 0.00 1.00 -0.61 -1.35 -1.35 0.74 0.74 0.74
## Income 2198 0.00 1.00 0.01 -2.41 -0.79 -0.02 0.81 3.00
## Kidhome 2198 0.00 1.00 0.64 -0.82 -0.82 -0.82 1.04 2.90
## Teenhome 2198 0.00 1.00 0.41 -0.93 -0.93 -0.93 0.91 2.74
## Recency 2198 0.00 1.00 0.00 -1.70 -0.87 0.00 0.86 1.73
## MntWines 2198 0.00 1.00 1.16 -0.91 -0.84 -0.38 0.59 3.51
## MntFruits 2198 0.00 1.00 2.10 -0.66 -0.61 -0.46 0.17 4.34
## MntMeatProducts 2198 0.00 1.00 1.82 -0.76 -0.69 -0.45 0.31 7.16
## MntFishProducts 2198 0.00 1.00 1.91 -0.69 -0.63 -0.47 0.23 4.05
## MntSweetProducts 2198 0.00 1.00 2.09 -0.66 -0.64 -0.47 0.17 5.70
## MntGoldProds 2198 0.00 1.00 1.83 -0.85 -0.68 -0.37 0.23 5.37
## NumDealsPurchases 2198 0.00 1.00 2.32 -1.23 -0.70 -0.17 0.36 6.73
## NumWebPurchases 2198 0.00 1.00 1.20 -1.50 -0.77 -0.04 0.70 8.37
## NumCatalogPurchases 2198 0.00 1.00 1.37 -0.95 -0.95 -0.23 0.48 9.07
## NumStorePurchases 2198 0.00 1.00 0.70 -1.79 -0.87 -0.25 0.67 2.21
## NumWebVisitsMonth 2198 0.00 1.00 0.23 -2.21 -0.97 0.27 0.69 6.08
## AcceptedCmp3 2198 0.07 0.26 3.26 0.00 0.00 0.00 0.00 1.00
## AcceptedCmp4 2198 0.07 0.26 3.24 0.00 0.00 0.00 0.00 1.00
## AcceptedCmp5 2198 0.07 0.26 3.29 0.00 0.00 0.00 0.00 1.00
## AcceptedCmp1 2198 0.06 0.25 3.56 0.00 0.00 0.00 0.00 1.00
## AcceptedCmp2 2198 0.01 0.12 8.38 0.00 0.00 0.00 0.00 1.00
## Response 2198 0.15 0.36 1.96 0.00 0.00 0.00 0.00 1.00
## Age 2198 0.00 1.00 0.09 -2.32 -0.69 -0.09 0.85 2.47
# Plot wss plot
wss_plot(market_st)
# Use NbClust function to validate number of clusters
NbClust(market_st,distance="euclidean",
min.nc = 2,max.nc = 5,method = "kmeans")
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 11 proposed 2 as the best number of clusters
## * 8 proposed 3 as the best number of clusters
## * 3 proposed 4 as the best number of clusters
## * 1 proposed 5 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 2
##
##
## *******************************************************************
## $All.index
## KL CH Hartigan CCC Scott Marriot TrCovW TraceW
## 2 3.6821 844.6114 282.0078 3.8909 4456.848 1.956188e+68 2542470 29205.39
## 3 2.8606 617.2604 127.0671 8.7286 7223.906 1.249858e+68 1827869 25881.69
## 4 4.2477 477.4669 58.5895 9.7371 9191.930 9.075778e+67 1610599 24465.41
## 5 0.2946 382.1361 94.0410 7.9294 10086.478 9.439596e+67 1515437 23829.06
## Friedman Rubin Cindex DB Silhouette Duda Pseudot2 Beale Ratkowsky
## 2 16.5831 1.3879 0.2376 1.6122 0.2682 1.2527 -326.3855 -3.3897 0.2723
## 3 20.9367 1.5661 0.2201 1.9489 0.1993 1.4036 -307.1163 -4.8282 0.2691
## 4 23.1961 1.6567 0.2214 2.1827 0.1270 1.1756 -115.0362 -2.5078 0.2475
## 5 23.8525 1.7010 0.2257 2.1692 0.1081 1.6078 -311.4936 -6.3453 0.2289
## Ball Ptbiserial Frey McClain Dunn Hubert SDindex Dindex SDbw
## 2 14602.694 0.5728 0.8331 0.6703 0.0596 1e-04 1.1824 3.5051 0.8449
## 3 8627.230 0.5647 -11.8495 1.2395 0.0457 1e-04 1.2549 3.2972 0.7882
## 4 6116.351 0.4304 -1.1512 2.1644 0.0496 1e-04 1.4305 3.1775 0.7187
## 5 4765.813 0.3640 0.0288 2.7278 0.0496 1e-04 1.4545 3.1180 0.6473
##
## $All.CriticalValues
## CritValue_Duda CritValue_PseudoT2 Fvalue_Beale
## 2 0.9481 88.6175 1
## 3 0.9370 71.8353 1
## 4 0.9343 54.1232 1
## 5 0.9340 58.1968 1
##
## $Best.nc
## KL CH Hartigan CCC Scott Marriot TrCovW
## Number_clusters 4.0000 2.0000 3.0000 4.0000 3.000 4.000000e+00 3.0
## Value_Index 4.2477 844.6114 154.9407 9.7371 2767.058 3.786623e+67 714600.3
## TraceW Friedman Rubin Cindex DB Silhouette Duda
## Number_clusters 3.00 3.0000 3.0000 3.0000 2.0000 2.0000 2.0000
## Value_Index 1907.41 4.3536 -0.0876 0.2201 1.6122 0.2682 1.2527
## PseudoT2 Beale Ratkowsky Ball PtBiserial Frey McClain
## Number_clusters 2.0000 2.0000 2.0000 3.000 2.0000 1 2.0000
## Value_Index -326.3855 -3.3897 0.2723 5975.464 0.5728 NA 0.6703
## Dunn Hubert SDindex Dindex SDbw
## Number_clusters 2.0000 0 2.0000 0 5.0000
## Value_Index 0.0596 0 1.1824 0 0.6473
##
## $Best.partition
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 2 1 2 1 1 2 2 1 1 1 1 2 1 1 2 1
## 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
## 1 2 1 1 2 1 2 1 1 1 1 2 1 1 1 1
## 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
## 2 1 2 1 1 2 2 1 1 1 2 1 1 2 2 2
## 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
## 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2
## 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
## 2 2 2 1 1 1 2 2 1 1 1 1 1 1 2 1
## 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
## 1 1 2 1 1 1 1 1 1 2 2 1 1 2 2 2
## 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
## 1 1 2 1 2 2 2 1 2 1 1 2 2 1 1 2
## 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
## 1 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2
## 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
## 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 1
## 145 146 147 148 149 150 152 153 154 155 156 157 158 159 160 161
## 1 2 1 2 1 2 1 2 1 2 1 1 1 1 1 1
## 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
## 2 2 1 1 2 1 1 2 1 1 1 1 2 2 1 1
## 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
## 2 1 1 1 2 2 2 1 1 2 2 2 1 1 1 1
## 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
## 1 2 1 2 1 1 2 1 1 2 1 2 1 2 2 1
## 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
## 2 1 1 2 2 1 1 2 1 1 2 1 1 2 1 2
## 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
## 2 1 2 2 1 2 2 2 2 1 1 2 1 2 1 2
## 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
## 1 1 1 1 2 1 1 1 1 2 1 2 1 2 1 1
## 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
## 1 1 2 2 2 2 2 1 1 1 2 1 1 2 2 2
## 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
## 1 1 1 2 1 1 2 1 1 2 2 1 2 1 1 1
## 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
## 2 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1
## 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
## 2 1 2 1 1 1 1 1 1 2 1 1 2 2 1 2
## 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
## 2 1 2 2 1 2 1 2 1 1 2 2 2 2 2 1
## 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
## 1 2 2 1 2 2 1 1 1 2 2 1 2 1 1 1
## 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
## 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2
## 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
## 1 2 2 1 2 1 2 2 1 1 1 1 1 2 1 1
## 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
## 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1
## 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
## 1 1 1 2 2 1 2 2 1 2 2 1 2 2 1 1
## 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
## 2 1 1 1 1 1 1 1 1 1 1 2 1 2 2 2
## 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
## 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 1
## 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
## 1 2 2 1 2 1 1 2 1 1 1 1 1 1 1 1
## 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
## 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2
## 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
## 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 2
## 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
## 1 1 2 2 1 2 1 2 1 1 2 2 2 1 2 2
## 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
## 1 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1
## 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
## 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2
## 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
## 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1
## 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
## 1 1 1 1 1 1 2 2 1 1 1 2 2 1 2 1
## 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
## 1 1 1 1 1 2 2 2 1 1 1 1 1 2 1 1
## 594 595 596 597 598 600 601 602 603 604 605 606 607 608 609 610
## 1 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1
## 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
## 1 2 2 2 1 2 1 2 2 2 2 2 2 2 1 2
## 627 628 629 630 631 632 633 634 635 636 638 639 640 641 642 643
## 1 2 1 2 2 2 1 2 1 1 1 1 2 1 1 1
## 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
## 2 1 1 1 1 1 1 1 2 1 2 2 1 1 2 2
## 660 661 662 663 664 665 666 667 668 670 671 672 673 674 675 676
## 1 2 2 2 1 1 2 2 2 2 2 1 2 1 1 1
## 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
## 1 1 1 2 2 2 2 2 2 1 2 1 1 2 1 1
## 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
## 2 1 2 1 2 2 1 2 1 2 2 1 2 1 1 2
## 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
## 2 1 2 1 1 1 1 2 2 2 2 1 2 2 1 1
## 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
## 1 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1
## 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
## 1 1 1 2 1 2 1 2 2 1 1 2 2 1 1 1
## 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
## 1 1 2 1 2 2 1 1 1 1 1 1 2 1 1 2
## 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
## 2 1 1 1 1 2 2 2 1 2 1 1 2 2 1 1
## 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
## 1 1 2 1 1 2 2 2 2 1 1 2 1 2 1 2
## 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
## 1 2 2 2 1 2 1 1 2 1 1 1 2 1 2 1
## 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
## 2 1 1 1 1 2 2 2 2 1 1 1 2 2 1 1
## 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
## 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2
## 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
## 2 1 1 2 2 1 1 2 1 1 1 1 1 2 2 1
## 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
## 1 1 2 1 1 2 1 2 2 2 2 1 1 2 1 2
## 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
## 1 1 2 2 1 1 1 2 2 2 1 2 2 2 2 1
## 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
## 2 1 2 1 1 2 1 2 2 2 2 2 1 2 1 2
## 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
## 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 1
## 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
## 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2
## 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
## 1 1 1 2 1 1 2 2 2 2 1 1 2 1 1 1
## 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
## 2 2 1 2 2 2 1 2 1 1 2 1 1 2 1 2
## 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
## 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 1
## 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
## 2 2 1 1 1 1 1 2 1 1 2 1 1 1 2 2
## 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
## 2 2 1 2 1 1 1 1 2 2 1 1 2 1 1 1
## 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
## 2 1 1 2 1 2 1 1 2 1 1 2 2 1 2 2
## 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
## 1 2 1 2 2 1 2 1 2 2 1 1 2 2 1 1
## 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
## 1 2 1 2 1 2 2 1 2 1 2 2 1 2 1 1
## 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
## 2 2 2 1 2 2 1 1 1 1 2 1 1 1 1 2
## 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
## 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2
## 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
## 1 1 2 2 1 1 2 2 1 1 2 1 1 2 1 1
## 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
## 1 2 1 1 1 1 1 2 2 1 2 1 1 1 2 2
## 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
## 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1
## 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
## 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 2
## 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
## 2 1 1 1 2 1 2 2 2 1 2 1 1 2 1 2
## 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
## 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 2
## 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
## 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1
## 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
## 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2
## 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
## 1 2 2 1 2 1 2 2 1 1 2 1 1 1 2 2
## 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
## 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 1
## 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1283 1284 1285
## 1 2 2 1 1 1 1 1 1 1 2 2 1 2 1 1
## 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
## 2 2 1 2 2 2 2 2 1 2 1 1 1 1 1 1
## 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
## 2 1 2 1 1 2 1 1 1 2 1 1 2 2 2 1
## 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
## 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
## 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
## 1 1 2 2 1 2 2 1 1 1 1 2 1 2 1 1
## 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
## 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1
## 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
## 1 2 1 1 1 1 1 2 1 1 2 1 1 2 1 1
## 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
## 1 1 1 2 1 1 2 2 1 2 1 1 1 1 1 1
## 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
## 1 2 2 1 1 1 1 1 1 2 1 1 2 1 1 1
## 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
## 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 2
## 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
## 2 1 1 2 1 1 2 2 1 2 1 1 1 2 1 2
## 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
## 1 2 1 1 1 2 2 1 2 1 1 2 2 2 1 1
## 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
## 2 2 2 1 2 1 2 1 2 1 1 2 1 1 2 2
## 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
## 1 1 1 1 2 2 1 2 2 2 2 1 2 2 1 1
## 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
## 2 1 1 1 2 2 1 1 1 1 2 1 2 1 2 1
## 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
## 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 1
## 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
## 2 1 1 2 2 2 2 1 1 1 1 2 1 1 1 2
## 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
## 1 1 2 2 1 1 2 1 2 1 1 1 1 2 1 1
## 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
## 1 2 2 1 2 1 1 2 1 2 1 2 1 1 1 1
## 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
## 1 1 2 1 1 2 2 1 1 1 2 1 1 2 2 1
## 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
## 2 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2
## 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
## 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1
## 1622 1623 1624 1625 1626 1627 1628 1629 1630 1632 1633 1634 1635 1636 1637 1638
## 2 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1
## 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
## 1 2 1 1 1 2 1 2 2 1 2 2 2 2 1 1
## 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
## 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1
## 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
## 1 1 2 1 2 1 2 2 1 1 1 1 1 2 1 2
## 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
## 1 2 2 1 2 1 1 2 1 1 2 1 2 2 2 1
## 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
## 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1
## 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
## 1 1 2 2 2 1 2 2 2 2 1 1 1 1 1 1
## 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
## 1 1 2 2 1 2 2 1 2 1 2 1 1 1 1 2
## 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
## 2 1 1 1 1 1 2 1 1 2 2 1 1 1 1 2
## 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
## 2 1 1 2 1 1 1 2 1 2 2 2 2 1 1 1
## 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
## 2 2 1 2 2 1 2 2 2 2 1 2 2 1 1 2
## 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
## 1 1 2 2 1 1 2 2 1 1 1 2 1 1 1 2
## 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
## 1 2 2 1 2 1 2 1 2 1 1 1 1 2 1 2
## 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
## 2 2 2 1 1 2 1 2 1 2 2 2 1 1 1 1
## 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
## 2 1 2 1 2 1 1 2 2 2 2 2 1 1 2 1
## 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
## 1 1 2 2 1 2 2 1 1 2 1 1 2 2 2 1
## 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
## 1 2 1 1 2 2 1 1 1 2 2 2 2 2 1 1
## 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
## 1 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1
## 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
## 1 2 1 1 2 1 1 2 1 1 2 1 2 2 2 1
## 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
## 1 1 2 2 2 1 2 1 1 2 1 2 2 1 1 1
## 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
## 2 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1
## 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
## 1 2 1 1 1 1 1 1 2 2 1 2 2 1 2 2
## 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
## 2 1 2 1 1 1 1 1 1 2 1 1 2 2 1 2
## 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
## 2 2 1 1 1 1 1 1 1 1 2 2 1 1 1 2
## 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
## 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 1
## 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
## 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 2
## 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
## 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 1
## 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
## 1 2 2 2 2 1 1 1 1 1 2 1 2 1 2 2
## 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086
## 1 2 1 2 1 1 1 2 1 2 1 2 1 1 1 2
## 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102
## 1 2 2 1 1 1 1 2 1 2 2 2 2 1 1 2
## 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
## 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1
## 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
## 1 2 1 1 1 1 1 1 2 1 2 1 1 2 1 1
## 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
## 2 2 2 1 1 2 2 2 2 2 2 1 1 1 1 1
## 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
## 1 1 2 2 2 2 1 2 1 1 2 2 1 1 1 1
## 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
## 1 1 2 2 1 1 2 1 1 1 1 2 1 2 1 1
## 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
## 1 2 1 1 1 2 1 1 2 1 1 1 1 1 2 1
## 2201 2202 2203 2204 2205 2206
## 1 2 1 2 2 1
NbClust simulates 30 different cluster analyses to identify the best number of clusters to use. Initially, we were recommended three clusters. However, the day before the presentation, we ran the function again and it recommended us two clusters. As we got two different suggestions from NbClust, we decided to use the WSS plot to determine how many clusters were best. After graphing the WSS plot, we agreed three clusters would be the optimal amount of clusters.
# Running Clustering
set.seed(123)
fit.km = kmeans(market_st, 3, nstart=30)
fit.km$size
## [1] 619 1001 578
fit.km$centers
## Education Marital_Status Income Kidhome Teenhome Recency
## 1 0.16410880 0.072784647 0.3072881 -0.4051375 0.7997385 -0.007932347
## 2 -0.08414919 -0.007520781 -0.8536860 0.6774618 -0.1392056 -0.002930381
## 3 -0.03001730 -0.064922829 1.1493570 -0.7393757 -0.6153864 0.013569955
## MntWines MntFruits MntMeatProducts MntFishProducts MntSweetProducts
## 1 0.4613912 -0.1410429 -0.1502551 -0.1692829 -0.1407135
## 2 -0.7875636 -0.5396513 -0.6540262 -0.5567876 -0.5380542
## 3 0.8698097 1.0856342 1.2935781 1.1455546 1.0825153
## MntGoldProds NumDealsPurchases NumWebPurchases NumCatalogPurchases
## 1 0.3040722 0.7276237 0.7870961 0.1384359
## 2 -0.5549601 -0.1354460 -0.7262023 -0.7564563
## 3 0.6354575 -0.5446671 0.4147336 1.1618010
## NumStorePurchases NumWebVisitsMonth AcceptedCmp3 AcceptedCmp4 AcceptedCmp5
## 1 0.5500896 0.1497328 0.06462036 0.13893376 0.02584814
## 2 -0.8114043 0.4998088 0.07392607 0.01098901 0.00000000
## 3 0.8161076 -1.0259398 0.08304498 0.11591696 0.24913495
## AcceptedCmp1 AcceptedCmp2 Response Age
## 1 0.035541195 0.019386107 0.1179321 0.37551093
## 2 0.000999001 0.001998002 0.0959041 -0.25954059
## 3 0.204152249 0.027681661 0.2785467 0.04733368
fit.km$cluster
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 3 2 3 2 1 1 1 2 2 2 2 3 1 2 3 2
## 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
## 2 1 2 2 3 1 1 1 2 2 2 3 2 2 2 1
## 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
## 3 2 1 2 2 3 3 2 2 2 3 2 2 1 1 3
## 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
## 2 3 1 3 3 2 1 3 1 1 1 3 2 2 3 1
## 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
## 1 3 1 1 2 2 3 3 2 1 2 2 2 2 3 2
## 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
## 2 1 3 2 2 2 2 1 2 3 1 2 2 3 3 3
## 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
## 2 2 1 2 3 3 1 1 3 1 2 3 1 2 2 1
## 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
## 2 2 2 3 3 3 2 1 1 3 2 3 2 2 2 3
## 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
## 1 3 1 2 1 2 2 2 2 1 1 1 1 1 1 2
## 145 146 147 148 149 150 152 153 154 155 156 157 158 159 160 161
## 2 3 2 1 2 3 2 3 2 3 2 2 2 2 2 2
## 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
## 3 3 2 2 3 2 2 3 2 2 2 2 1 3 2 2
## 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
## 3 2 2 2 1 3 3 2 1 3 1 3 2 2 2 1
## 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
## 2 1 1 3 1 1 3 1 2 3 1 1 2 3 1 2
## 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
## 1 2 1 1 3 2 1 3 2 2 1 2 2 1 2 3
## 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
## 3 2 3 1 2 3 1 3 3 2 2 3 2 1 2 1
## 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
## 1 2 2 2 1 2 2 1 2 3 2 3 2 3 2 1
## 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
## 2 2 1 3 3 3 1 2 1 2 1 2 2 3 1 3
## 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
## 1 2 2 3 2 2 1 2 2 3 1 2 1 2 2 2
## 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
## 3 2 3 1 2 2 2 3 1 2 2 2 2 1 2 2
## 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
## 1 1 3 2 2 2 2 2 2 1 2 2 3 3 2 3
## 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
## 3 2 1 1 2 3 2 3 2 2 1 3 3 3 1 2
## 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
## 2 3 1 1 3 1 2 2 1 1 3 2 3 1 2 2
## 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
## 2 1 2 2 2 2 1 2 2 2 2 2 2 2 1 1
## 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
## 2 1 3 2 3 2 1 3 2 2 2 2 2 3 2 2
## 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
## 1 2 2 2 2 1 2 1 1 2 1 3 2 3 3 1
## 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
## 2 2 2 3 3 2 3 1 2 3 3 1 1 1 2 2
## 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
## 1 1 2 2 2 1 2 2 2 2 2 3 2 1 1 1
## 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
## 2 1 1 1 3 2 1 3 1 3 2 3 2 3 3 2
## 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
## 1 1 3 2 1 2 2 1 2 1 1 1 2 2 2 1
## 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
## 3 3 1 1 2 2 3 2 3 1 1 1 2 1 1 3
## 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
## 2 2 2 1 2 1 3 3 2 1 2 3 1 3 1 3
## 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
## 2 2 3 3 2 3 2 3 2 2 3 1 3 1 1 3
## 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
## 1 2 2 1 2 3 1 2 2 2 2 3 1 2 3 2
## 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
## 2 2 2 2 1 2 3 2 3 3 2 3 2 3 1 3
## 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
## 1 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1
## 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
## 2 1 2 2 2 2 3 1 1 2 2 3 3 2 3 2
## 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
## 2 2 2 2 2 1 3 1 2 2 2 2 2 3 2 2
## 594 595 596 597 598 600 601 602 603 604 605 606 607 608 609 610
## 2 2 3 1 2 2 1 1 2 3 2 3 2 3 3 2
## 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
## 2 1 3 3 2 3 2 3 1 1 1 1 3 1 1 3
## 627 628 629 630 631 632 633 634 635 636 638 639 640 641 642 643
## 2 3 2 1 1 3 2 1 2 1 2 2 3 1 1 2
## 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
## 3 2 2 2 2 2 2 2 3 1 3 3 1 2 1 3
## 660 661 662 663 664 665 666 667 668 670 671 672 673 674 675 676
## 2 3 1 3 1 1 3 1 3 3 3 1 3 1 2 2
## 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
## 1 2 2 1 3 1 3 1 3 2 3 2 1 1 2 2
## 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
## 1 2 1 2 3 3 2 1 2 1 1 2 3 2 2 3
## 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
## 3 1 3 2 1 1 1 1 3 3 1 2 3 1 2 2
## 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
## 2 3 3 2 3 2 3 3 1 3 3 3 3 1 1 2
## 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
## 2 2 1 3 2 3 1 3 3 2 1 1 3 1 2 2
## 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
## 2 2 3 2 3 3 2 2 2 2 2 2 1 1 1 3
## 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
## 3 2 2 2 2 1 1 3 2 1 2 2 3 3 1 2
## 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
## 1 1 3 2 2 3 1 3 1 2 1 1 2 3 2 1
## 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
## 2 3 3 1 2 3 2 2 1 1 2 2 3 2 3 2
## 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
## 1 2 1 2 2 3 3 3 1 2 2 1 1 3 2 1
## 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
## 3 2 1 2 3 2 1 2 2 2 1 1 2 1 2 3
## 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
## 1 2 2 3 3 1 2 3 2 2 2 2 2 3 3 2
## 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
## 2 1 3 2 1 3 2 3 1 3 3 2 2 3 2 3
## 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
## 1 1 3 3 2 2 2 3 3 1 2 3 3 3 3 1
## 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
## 3 2 3 2 2 3 1 3 3 3 3 3 2 1 2 3
## 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
## 2 3 1 1 1 1 1 3 3 2 1 1 2 2 1 2
## 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
## 2 2 2 2 2 1 1 2 1 3 1 2 2 2 1 3
## 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
## 2 2 1 3 2 2 1 3 3 3 1 2 1 2 2 2
## 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
## 1 3 1 3 3 3 2 3 2 1 3 2 2 3 2 3
## 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
## 1 1 3 1 2 1 1 1 3 2 2 3 2 2 2 2
## 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
## 1 3 2 2 2 2 2 1 2 2 1 2 2 2 1 3
## 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
## 3 3 2 3 2 2 2 2 1 1 2 2 3 2 2 2
## 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
## 3 1 1 3 2 3 2 2 3 1 2 3 3 1 1 3
## 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
## 2 1 2 3 1 2 3 2 3 1 2 1 3 3 2 2
## 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
## 2 3 2 3 2 3 1 2 3 2 3 3 2 3 2 2
## 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
## 1 1 3 2 1 3 1 2 2 2 3 2 2 1 1 3
## 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
## 3 2 3 2 1 2 2 2 1 1 2 1 2 1 1 1
## 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
## 2 2 3 1 2 2 3 3 2 2 3 2 1 1 2 2
## 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
## 2 3 2 2 1 1 2 1 3 2 3 1 2 1 3 3
## 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
## 3 1 1 1 3 2 1 2 2 3 3 2 2 3 1 2
## 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
## 1 2 1 2 3 1 2 1 2 2 2 2 1 2 2 3
## 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
## 1 2 2 2 1 2 1 3 3 2 1 1 2 3 1 3
## 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
## 2 2 2 1 3 3 3 1 2 1 2 3 2 2 2 3
## 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
## 2 2 1 1 2 1 2 2 2 2 2 2 1 2 3 2
## 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
## 2 2 2 3 3 2 2 2 2 2 1 3 1 3 3 1
## 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
## 1 1 3 2 3 2 3 3 2 2 3 1 2 2 3 1
## 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
## 1 2 1 2 1 2 2 3 1 3 3 2 1 1 2 1
## 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1283 1284 1285
## 2 3 3 2 2 2 2 2 1 2 1 3 2 3 2 2
## 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
## 3 1 1 3 1 1 1 3 1 3 2 2 1 2 2 2
## 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
## 3 1 3 2 2 1 2 2 2 3 2 1 3 3 3 1
## 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
## 3 2 2 2 1 1 1 2 2 2 2 1 1 3 3 3
## 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
## 2 1 3 3 2 3 3 2 1 2 1 3 1 3 1 2
## 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
## 2 1 2 2 2 1 1 1 1 2 1 2 2 2 3 2
## 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
## 2 3 1 2 2 2 2 1 2 2 1 1 1 1 2 1
## 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
## 1 2 1 1 1 2 1 3 2 3 2 1 2 2 2 2
## 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
## 2 3 1 2 2 2 2 2 2 1 2 2 3 2 1 2
## 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
## 1 2 2 2 2 2 2 3 3 2 3 1 3 1 2 3
## 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
## 3 2 1 3 2 2 3 1 1 1 2 2 2 1 1 3
## 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
## 2 1 2 2 2 1 1 2 3 2 2 1 3 1 2 2
## 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
## 3 1 3 1 3 2 1 2 3 1 2 3 2 1 1 3
## 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
## 1 2 2 1 1 1 1 3 3 1 3 2 3 3 2 2
## 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
## 1 2 2 2 3 3 2 2 2 1 3 2 3 2 1 1
## 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
## 1 2 2 2 2 3 1 1 2 1 3 2 1 2 2 2
## 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
## 1 2 2 3 3 3 1 2 1 2 2 1 2 1 2 3
## 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
## 2 1 1 1 1 1 3 2 3 2 2 1 2 3 2 1
## 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
## 2 3 3 2 3 2 2 3 2 3 2 3 2 1 2 1
## 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
## 2 2 3 2 1 3 3 2 2 2 3 1 1 1 3 2
## 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
## 3 2 2 3 2 2 1 1 2 2 3 1 2 1 1 3
## 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
## 2 2 3 2 2 2 1 1 1 3 2 2 2 1 1 2
## 1622 1623 1624 1625 1626 1627 1628 1629 1630 1632 1633 1634 1635 1636 1637 1638
## 3 2 1 3 3 2 2 3 2 2 2 1 1 1 3 1
## 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
## 2 1 2 2 2 1 2 1 3 2 3 3 3 3 2 2
## 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
## 2 2 2 3 2 2 2 1 2 3 1 1 3 1 3 2
## 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
## 2 2 3 2 3 2 3 1 2 2 1 2 2 1 1 3
## 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
## 1 3 3 2 3 2 1 1 2 2 1 2 3 3 3 2
## 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
## 2 2 2 1 3 2 2 2 3 3 1 1 3 1 2 2
## 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
## 2 2 3 1 3 2 3 1 3 1 1 2 1 2 2 2
## 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
## 2 2 3 1 2 1 1 2 1 2 3 2 2 2 2 3
## 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
## 3 2 2 2 2 2 3 2 2 3 1 2 2 1 2 1
## 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
## 3 2 2 3 2 2 2 1 2 1 3 3 3 2 1 2
## 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
## 1 1 2 3 3 2 1 3 3 3 2 1 3 1 2 1
## 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
## 2 2 3 3 2 1 3 3 2 2 2 1 2 2 2 3
## 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
## 1 1 1 2 3 2 3 1 3 2 2 1 2 3 2 3
## 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
## 3 3 1 2 2 3 1 1 2 1 3 3 1 2 2 2
## 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
## 3 2 3 2 1 2 2 1 3 1 3 3 2 2 1 2
## 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
## 2 2 3 1 2 3 3 2 1 3 1 2 3 3 1 2
## 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
## 2 1 2 1 3 1 2 2 2 3 3 3 3 1 1 2
## 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
## 2 2 2 2 3 3 3 3 2 1 3 3 1 2 1 2
## 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
## 2 3 2 1 1 2 2 3 2 2 3 2 3 3 3 2
## 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
## 2 2 1 3 3 1 3 2 1 3 2 3 1 2 2 2
## 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
## 3 1 3 3 3 1 2 2 1 2 1 3 2 2 2 2
## 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
## 2 3 2 1 2 2 2 2 1 3 2 3 3 2 3 3
## 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
## 1 2 1 2 2 2 2 2 2 3 1 1 1 3 2 3
## 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
## 3 3 2 2 2 2 2 2 2 1 1 1 2 2 2 1
## 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
## 2 1 1 2 3 2 1 1 1 2 3 3 1 2 2 1
## 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
## 2 2 3 3 3 2 1 1 2 2 2 3 1 1 2 3
## 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
## 2 1 3 2 1 2 2 1 3 2 3 3 3 2 2 2
## 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
## 1 3 1 3 3 2 2 1 2 1 1 2 3 1 3 1
## 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086
## 2 1 2 1 2 2 2 1 1 3 1 1 2 2 1 1
## 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102
## 2 1 3 2 2 2 2 1 2 3 1 3 1 2 2 3
## 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
## 2 1 2 2 1 2 2 2 2 2 1 3 2 2 1 2
## 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
## 2 3 2 2 2 2 2 2 1 1 1 2 1 3 2 2
## 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
## 3 3 3 2 1 1 3 1 1 3 3 1 1 2 1 2
## 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
## 2 2 1 1 3 3 2 3 2 2 3 1 2 2 1 1
## 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
## 2 2 1 3 2 2 3 2 2 2 1 3 2 3 2 2
## 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
## 2 3 2 2 1 3 2 2 1 1 1 1 2 2 1 2
## 2201 2202 2203 2204 2205 2206
## 2 1 1 3 1 2
market_st$cluster = fit.km$cluster
# Plots
profile_plot(market_st, type="line")
profile_plot(market_st, type="bar")
# Add Clustering to market df
market$cluster = factor(fit.km$cluster)
# Add PCA to market df
market = score(market, fit)
fviz_cluster(fit.km, market_st, geom = "point",
ellipse.type = "norm",
repel=T)
Graphing Variables for Analysis
#Graphing Income
ggplot(market, aes(x=cluster, y=Income)) +
geom_boxplot() +
labs(title="Total Income per Cluster")
After plotting income, we saw Cluster 3 had the highest average income followed by Cluster 1 and Cluster 2.
#Graphing Marital Status
crosstab(market, Marital_Status, cluster,
type = "colpercent",
plot=T)
Cluster 1 has the greatest percentage of married people, followed by Cluster 2 and Cluster 3. The difference between the three clusters is small, though.
#Graphing Education
crosstab(market, Education, cluster,
type = "colpercent",
plot=T)
Cluster 1 had the greatest percentage of people with high level education. Cluster 2 had a greater percentage of people with high level education compared to Cluster 3, but had more people with no college education.
#Graphing Kid at Home
crosstab(market, Kidhome, cluster,
type = "colpercent",
plot=T)
Most of Cluster 3 did not have kids at home, while many of Cluster 1 did not either. Majority of Cluster 2 had at least 1 child.
#Graphing Teenhome
crosstab(market, Teenhome, cluster,
type = "colpercent",
plot=T)
Majority of Cluster 1 had a teenager at home, while nearly half of Cluster 2 did as well. 83% of Cluster 3 did not have teens at home.
#Response
crosstab(market, Response, cluster,
type = "colpercent",
plot=T)
Cluster 1 and 2 did not seem to be interested in marketing campaigns, while Cluster 3 seemed the most interested.
#Age
ggplot(market, aes(x=cluster, y=Age)) +
geom_boxplot()
age_clust = market %>%
group_by(cluster) %>%
summarize(avg_age = mean(Age, na.rm=TRUE))
All clusters were in a similar age range, with Cluster 1 being the oldest and Cluster 2 the youngest.
#Purchases of products
library(reshape2)
market %>%
select(cluster, MntWines, MntFruits, MntFishProducts,
MntMeatProducts, MntSweetProducts, MntGoldProds)%>%
melt(id='cluster')%>%
ggplot(aes(as_factor(cluster), value))+
geom_boxplot()+
facet_wrap(~variable, ncol=5)
market %>%
select(cluster, MntFruits, MntFishProducts,
MntSweetProducts, MntGoldProds)%>%
melt(id='cluster')%>%
ggplot(aes(as_factor(cluster), value))+
geom_boxplot()+
facet_wrap(~variable, ncol=5)
market %>%
select(cluster, MntWines, MntMeatProducts)%>%
melt(id='cluster')%>%
ggplot(aes(as_factor(cluster), value))+
geom_boxplot()+
facet_wrap(~variable, ncol=5)
To observe what items people purchased, we made two separate charts
to better visualize the data.
Cluster 3 bought the most of every item. Cluster 1 seemed more
interested in gold and wine products than some of the products. On
average, Cluster 2 did buy a large amount of items across all
categories
#Purchase Platform
market %>%
select(cluster, NumDealsPurchases, NumWebPurchases,
NumCatalogPurchases, NumStorePurchases,
NumWebVisitsMonth) %>%
melt(id='cluster')%>%
ggplot(aes(as_factor(cluster), value))+
geom_boxplot()+
facet_wrap(~variable, ncol=5)
People in Cluster 1 tend to shop the most deals, while also shopping online and in store. Cluster 3 seems to prefer to shop in store and through catalogs– but do not seem to shop the deals. Cluster 2 shops in store more but also visits the website the most.
#Accepted Campaigns per Cluster
market %>%
select(cluster, AcceptedCmp3,
AcceptedCmp5, AcceptedCmp4,
AcceptedCmp1, AcceptedCmp2) %>%
melt(id='cluster')%>%
ggplot(aes(as_factor(cluster), value))+
geom_col()+
facet_wrap(~variable, ncol=5)
#Recency Histogram
ggplot(market, aes(x = Recency)) +
geom_histogram(bins = 20) +
facet_wrap(~cluster)
Following our analysis of the acceptance of marketing campaigns, we
chose to not come to any conclusion regarding those results - as we do
not know what each campaign comprised of.
Overall, we noticed that Cluster 2 seems to purchase the fewest items
but seem to shop more in store than anywhere else.
Cluster 2 did lead all clusters in online visits, however. Cluster 3
seems to be the wealthiest cluster and therefore was the cluster that
made the most purchases. Age, marital status, and education seemed
evenly distributed between clusters. Cluster 1 was the cluster that was
in between Cluster 2 and Cluster 3.
Cluster 1 Characteristics
Cluster 1 Recommendations
Cluster 1 is the cluster with the second highest purchasing power across all product categories and the highest number of online purchases. Members of this cluster also shop deals often. Because they have the most online purchases, one recommendation for the business would be to increase the amount of online promotions for this cluster. This can include marketing strategies such as email marketing campaigns, targeted ads on Google and other social media, and offering more online deals. It was also noted that this cluster buys a decent amount of wine and gold. Therefore, wine and gold can be the subject of the targeted ads and deals to minimize marketing cost per sale. Strategic promotions in-store and through physical mail are also recommended.
Cluster 2 Characteristics
Cluster 2 Recommendations
Cluster 2 is the cluster with the lowest purchasing power across all product categories and platforms. However, one interesting finding is that they have the highest number of website visits and the highest percentage of having kids. That is, this cluster visits the website the most but does not purchase often. Because of this, our recommendations would be to make the website more enticing and make online deals or offers more visible and easily accessible. One way of doing this would be to design the website with a clean layout of products and take clear product photos. This may attract more website purchases from this cluster. Another way to implement this is to have a section for special deals, like “Savers Deals”, and promote deals for products often bought by parents such as kids’ snacks, toys and expensive nutritious foods. Another recommendation would be to promote online shopping in-store by highlighting the benefits of purchasing through the website.
Cluster 3 Characteristics
Cluster 3 Recommendations
Cluster 3 is the cluster with the highest purchasing power across all product categories and earns the most income. Almost all members of the cluster do not have kids. Another interesting finding is that they have the most in-store and catalog purchases but also has the lowest web visits. Based on this, our recommendations are focused on making adjustments in-store and in the catalog. As they are the most frequent purchasers of wine and meat, one recommendation would be to place the wines and meats together in-store to encourage complementary sales. Another recommendation would be to send them customized catalogs that are focused on more expensive and luxurious products of each product category. Additionally, these products can be advertised to this cluster in-store and they can be encouraged to try shopping on the website by highlighting the benefits.
Because the NbClust function recommended us two clusters after the fact that we made our analyses using its initial suggestion of three clusters, one suggestion would be to run a k-means cluster analysis with two clusters and see how the results differ from three clusters. Also, an algorithm can be used to identify the most important features of the data set before running a PCA analysis and cluster analysis.